package com.brave.mvvm.helper

import android.app.Application
import android.util.Log
import android.view.View
import androidx.databinding.ObservableField
import com.blankj.utilcode.util.ToastUtils
import com.brave.mvvm.helper.core.net.HttpApi
import com.brave.mvvm.helper.core.net.RetrofitUtils
import com.brave.mvvm.mvvmhelper.base.CommonViewModel
import com.brave.mvvm.mvvmhelper.utils.subscribeNew


class TestViewModel : CommonViewModel<HttpDataModel> {
    constructor(application: Application) : super(application)
    constructor(application: Application, model: HttpDataModel?) : super(application, model)

    private var httpApi: HttpApi? = null
    fun getHttpApi(): HttpApi {
        if (null == httpApi) {
            httpApi = RetrofitUtils.instance
                .create(HttpApi::class.java)
        }
        return httpApi!!
    }


    var mTestText = ObservableField("123456")
    var url =
        ObservableField("https://img-blog.csdnimg.cn/20201014180756754.png?x-oss-process=image/resize,m_fixed,h_64,w_64")
    var placeholder = ObservableField(R.mipmap.ic_launcher)

    // 点击1
    val onClickCommand: (View) -> Unit = { _: View ->
        ToastUtils.showLong("奠基石")
    }

    // 点击2
    val onClickCommand0: (View) -> Unit = { _: View ->
        ToastUtils.showLong("奠基石000")
        getHttpApi().shopStoreDiyPage().subscribeNew({
            Log.d(TAG, "call: $it")
        }, {
            Log.d(TAG, "call: ${it?.message}")
        }, {
            Log.d(TAG, "call: =============================")
        })
    }

    companion object {
        private const val TAG = "TestViewModel"
    }
}